package 学生成绩发布系统;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Dbutil {
    public static Connection getConnection() {

        Connection conn = null;

        PreparedStatement pre = null;

        ResultSet result = null;

        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String username = "system";
        String password = "123456";

        String className = "oracle.jdbc.driver.OracleDriver";
        try {
            Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try {
            conn = DriverManager.getConnection(url, username, password);
            System.out.println("数据库连接建立成功...");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void close(Connection c) {
        if (c != null) {
            try {
                c.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(PreparedStatement c) {
        if (c != null) {
            try {
                c.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
